package com.jinmei.utils;

import java.net.URLDecoder;

import javax.servlet.http.HttpServletRequest;

import com.jinmei.model.Employee;
import com.jinmei.model.ToDoList;

public class TaskActionUtils {
	
	public static ToDoList convertRequestPar2Task(HttpServletRequest request) throws Exception{
		ToDoList task = new ToDoList();
		
		if(request.getParameter("id") != null){
			task.setId(Integer.valueOf(request.getParameter("id")));
		}
		if(request.getParameter("startDateTime") != null){
			task.setStartDateTime(StringUtil.convertString2Date(URLDecoder.decode(request.getParameter("startDateTime"), JinmeiConsts.ENCODING)));
		}
		if(request.getParameter("endDateTime") != null){
			task.setEndDateTime(StringUtil.convertString2Date(URLDecoder.decode(request.getParameter("endDateTime"), JinmeiConsts.ENCODING)));
		}
		if(request.getParameter("subject") != null){
			task.setSubject(URLDecoder.decode(request.getParameter("subject"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("contents") != null){
			task.setContents(URLDecoder.decode(request.getParameter("contents"), JinmeiConsts.ENCODING));
		}
		if(request.getParameter("isCompleted") != null){
			task.setIsCompleted(Integer.valueOf(request.getParameter("isCompleted")));
		}
		if(request.getParameter("FID") != null){
			Employee employee = new Employee();
			employee.setfId(Integer.valueOf(request.getParameter("FID")));
			task.setEmployee(employee);
		}
		return task;
	}
	
}
